package com.sundi.ecsystem.web;


import com.sundi.eccommon.dto.RoleMenuDto;
import com.sundi.eccommon.vo.ResultEntity;
import com.sundi.ecsystem.entity.EcRoleMenu;
import com.sundi.ecsystem.service.IEcRoleMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Mht
 * @since 2020-02-25
 */
@RestController
@RequestMapping("/ecRoleMenu")
public class EcRoleMenuController {

    @Autowired
    IEcRoleMenuService roleMenuService;

    @RequestMapping(value = "shouquanUpdate",method = RequestMethod.POST)
    public ResultEntity save(@RequestBody RoleMenuDto roleMenuDto){
        List<EcRoleMenu> menuRoleList = new ArrayList<>();
        for (Integer integer : roleMenuDto.getMenuIdList()) {
            EcRoleMenu menuRole = new EcRoleMenu();
            menuRole.setMenuId(integer);
            menuRole.setRoleId(roleMenuDto.getRid());
            menuRoleList.add(menuRole);
        }
        roleMenuService.save(menuRoleList);
        return ResultEntity.ok("成功授权菜单");
    }



}
